<template>
	<view class="tpl-index with-navbar">
		<view class="search-box">
			<input type="search" v-model="searchValue.name" placeholder="输入关键词来搜索" />
			<view class="btn" @click="search">搜索</view>
		</view>

		<swiper class="swiper">
			<swiper-item v-for="(one, index) of banners" :key="index">
				<image previous-margin="20upx" next-margin="20upx" class="banner" :src="one" mode="widthFix"></image>
			</swiper-item>
		</swiper>

		<view class="menu">
			<navigator :url="one.url" class="one" v-for="(one, index) of menu" :key="index" @click="pageTo(one)">
				<!-- <image class="image" :src="one.image" mode=""></image> -->
				<view class="icon-box"><text class="iconfont " :class="[one.icon]"></text></view>
				<text class="text">{{ one.name }}</text>
			</navigator>
		</view>
		<view class="menu menu2">
			<navigator :url="one.url" class="one" v-for="(one, index) of menu2" :key="index" @click="pageTo(one)">
				<!-- <image class="image" :src="one.image" mode=""></image> -->
				<view class="icon-box"><text class="iconfont " :class="[one.icon]"></text></view>
				<text class="text">{{ one.name }}</text>
			</navigator>
		</view>

		<view class="ul with-li-cards with-have-no-mt with-have-no-click-bg">
			<view class="title-box">
				<view class="title">荷式拍卖列表</view>
				<!-- <text class="iconfont icon-right"></text> -->
			</view>
			<view class="li-cards">
				<view class="li-box" v-for="(item,index) of list" :key="index">
					<view class="li" @click="jumps(item)">
						<image :src="global+item.image" class="icon" mode="aspectFill"></image>
						<view class="name">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import apis from '@/api/index.js'
	import G from '../../config/global';
	import {
		requestApi
	} from '@/utils/request.js'
	// 导入公共组件方法
	import common from '@/common/js/common.js';
	export default {
		mixins: [common],
		data() {
			return {
				searchValue:{
					sellType:"1",
					status:1
				},
				menu2: [],
				global:G.REQUEST_URL,
				menu: [],
				list:[],
				banners: [
					'/static/index/q.jpg',
				]
			};
		},
		onLoad() {
			this.getIndex();
			this.orderList();
		},
		methods: {
			pageTo(item){
				uni.reLaunch({
					url:"/pages/cart/cart?type="+item.typeId
				})
			},
			orderList(){
				requestApi(apis.productstype.list,this.productstype,"get").then(res=>{
					this.menu = res.data.slice(0,4);
					this.menu.forEach(item=>{
						item.name = item.typeName;
					})
					this.menu2 = res.data.slice(4,8);
					this.menu2.forEach(item=>{
						item.name = item.typeName;
					})
				})
			},
			getIndex() {
				requestApi(apis.products.list,this.searchValue, 'GET').then(res => {
					uni.hideLoading();
					console.log(res);
					if (res.code === 200) {
						this.list = res.data;
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						});
					}
				}).catch(res => {
					uni.showToast({
						icon: 'none',
						title: res.msg
					});
				});
			},
			search(){
				console.log(this.searchValue);
				this.getIndex();
			},
			jumps(item){
				uni.navigateTo({
					url:"/pages/goods-detail/goods-detail?id="+item.productId
				})
			}
		}
	};
</script>

<style>
	page {
		background-color: #fff;
	}
</style>

<style lang="scss" scoped>
	.tpl-index {
		// padding-top:calc(100upx + var(--status-bar-height)) ;
		// 	padding-top: var(--status-bar-height);
		// 	margin-top: 100upx;
		background-color: #FFF;

		.menu {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			padding: 0 30upx;

			&.menu2 {
				.one {
					margin-bottom: 20upx;

					&:nth-child(1) {
						.icon-box {
							background-color: rgb(250, 160, 80);
						}
					}

					&:nth-child(2) {
						.icon-box {
							background-color: rgb(100, 210, 220);
						}
					}

					&:nth-child(3) {
						.icon-box {
							background-color: rgb(20, 170, 240);
						}
					}

					&:nth-child(4) {
						.icon-box {
							background-color: rgb(94, 210, 240);
						}
					}
				}
			}

			.one {
				// 			width: 186upx;
				// 			max-width: 186upx;
				display: flex;
				flex-direction: column;
				font-size: $uni-font-size-sm;
				justify-content: center;
				align-items: center;
				margin-bottom: 36upx;

				&:nth-child(1) {
					.icon-box {
						background-color: rgb(20, 170, 240);
					}
				}

				&:nth-child(2) {
					.icon-box {
						background-color: rgb(94, 210, 240);
					}
				}

				&:nth-child(3) {
					.icon-box {
						background-color: rgb(250, 160, 80);
					}
				}

				&:nth-child(4) {
					.icon-box {
						background-color: rgb(250, 125, 130);
					}
				}

				.image {
					width: 90upx;
					height: 90upx;
					border-radius: 100upx;
					margin-bottom: 16upx;
					box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
				}

				.icon-box {
					width: 90upx;
					height: 90upx;
					border-radius: 100upx;
					margin-bottom: 16upx;
					box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
					display: flex;
					align-items: center;
					justify-content: center;

					text {
						font-size: 46upx;
						color: #fff;
					}
				}

				.text {
					color: #666;
					text-align: center;
					display: flex;
					justify-content: center;
				}
			}
		}

		.swiper {
			margin-top: 120upx;
			width: 710upx;
			min-height: 338upx;
			margin-left: 20upx;
			border-radius: 40upx;
			box-shadow: 0 5px 20px rgba(10, 170, 210, 0.1);
			margin-bottom: 40upx;
			overflow: hidden;

			.banner {
				width: 100%;
				height: 100%;
				border-radius: 40upx;
			}
		}

		.search-box {
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20upx;
			position: fixed;
			left: 0;
			right: 0;
			// top: var(--status-bar-height);
			top: 0;
			font-size: $uni-font-size-sm;
			z-index: 100;
			padding-top: var(--status-bar-height);
			// #ifndef APP-PLUS
			padding-top: 20upx;

			// #endif
			input {
				background-color: #eee;
				flex: 1;
				border-radius: 50upx;
				padding: 0 20upx;
				height: 60upx;
				line-height: 60upx;
				display: flex;
				align-items: center;
			}

			.btn {
				margin-left: 20upx;
				height: 60upx;
				line-height: 60upx;
			}
		}
	}
</style>